package org.association.builder_state;

import java.util.ArrayList;

public class Context {
	public final static ConcreteStateA CONCRETE_STATE_A = new ConcreteStateA();
	public final static ConcreteStateB CONCRETE_STATE_B = new ConcreteStateB();
	public final static ConcreteStateC CONCRETE_STATE_C = new ConcreteStateC();
	public final static ConcreteStateD CONCRETE_STATE_D = new ConcreteStateD();

	private State currentState;

	private ArrayList<String> orderList = new ArrayList<String>();

	public State getCurrentState() {
		return currentState;
	}

	public void setCurrentState(State currentState) {
		this.currentState = currentState;
		this.currentState.setContext(this);
	}

	public void setOrderList(ArrayList<String> orderList) {
		this.orderList = orderList;
	}

	public void methodA() {
		this.currentState.methodA();
	}

	public void methodB() {
		this.currentState.methodB();
	}

	public void methodC() {
		this.currentState.methodC();
	}

	public void methodD() {
		this.currentState.methodD();
	}

	public void templeMethod() {
		for (int i = 0; i < orderList.size(); i++) {
			String actionName = orderList.get(i);
			if (actionName.equalsIgnoreCase("A"))
				this.methodA();
			else if (actionName.equalsIgnoreCase("B"))
				this.methodB();
			else if (actionName.equalsIgnoreCase("C"))
				this.methodC();
			else if (actionName.equalsIgnoreCase("D"))
				this.methodD();

		}
	}
}
